// ignore_for_file: file_names

import 'dart:convert';

import 'package:shared_preferences/shared_preferences.dart';

class LocalStorage {
  static setInt(String key, int val) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return await prefs.setInt(key, val);
  }

  static setBool(String key, bool val) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return await prefs.setBool(key, val);
  }

  static setDouble(String key, double val) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return await prefs.setDouble(key, val);
  }

  static setString(String key, String val) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return await prefs.setString(key, val);
  }

  static setStringList(String key, List<String> val) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return await prefs.setStringList(key, val);
  }

  static setJson(String key, dynamic jsonObj) async {
    return await setString(key, jsonEncode(jsonObj));
  }

  static getInt(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getInt(key);
  }

  static getBool(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getBool(key);
  }

  static getDouble(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getDouble(key);
  }

  static getString(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(key);
  }

  static getStringList(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getStringList(key);
  }

  static getJson(String key) async {
    String? str = await getString(key);
    if (str != null) {
      return jsonDecode(str);
    }
    return null;
  }
}
